// view/zhuce/zhuce.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    getiOrqyid:'',
    getiOrqyname:"请选择企业类别",
    getiOrqy:[{id:0,title:'个体商户'},{id:1,title:'企业或公司'}],
    mobelphone:'', // 手机号
    cjzp:'',  //场景照片
    wucjzp:'',
    yhkZM:'', // 银行卡正面
    wuyhkZM:'',
    yhkFM:'', // 银行卡反面
    
    Paymentcode:'', // 支付码照片
    wuPaymentcode:'',  // 无域名支付码照片
    pay_type:0,
    wuyhkFM:'', 
    buttonClicked: false,
    s2: false,
    yuming: yuming,
    heights: "",
    title: '注册信息',
    hanglist: [{
      ame: '餐饮业态'
    }, {
      name: '企业'
    }], //行业类别
    ytList: [],
    jylxList:[],
    content:'',
    otherhyList: [],
    jingyinglx:[],
    getiOrqyindex:0,
    hangindex: 0, //行业index
    ytindex: 0, //业态分类index
    jylxindex:0, // 经营类型index
    otherhyindex: 0, //其他行业index
    jielist: [{
      name: '乡企城'
    }, {
      name: '稻香街'
    }], //所属街道
    jieindex: 0, //所属街道index
    shengguo: '请选择省',
    shiguo: '请选择市',
    quguo: '请选择区',
    shenglist: [],
    shilist: [],
    qulist: [],
    shengindex: 0,
    shiindex: 0,
    quindex: 0,
    jiangslist: [], //所属监管所
    suoshufenju:false,   // 所属分局显示与隐藏
    jiangsindex: 0,
    myjgylist: [], //我的监管员
    myjgyindex: 0,
    hangyeguo: '行业类别', //行业类别
    yetaiguo: '请选择业态分类', //业态分类
    yetaiguojylx:'请选择经营类型',
    yetaiguojylxid:'',  // 经营信息id
    otherhyguo: '请选择其他行业',
    jiangsguo: '请选择所属监管所', //所属监管所
    jieguo: '请选择所属市场/街道', //所属市场
    myjgyguo: '请选择', //我的监管员
    myjgyguoJH:'请选择网格员',
    jianguansuoTWO:'',
    jianguansuoTWOname:'请选择监管所', // 监管所2
    jgsidTWO:'',  // 监管所id 2
    zhengs: [{
        tit: '营业执照',
        state: 0,
        img: 'https://msion.xazbwl.com/static/applet/images/index/pho.png',
        tishi: '上传最新的营业执照正本或副本'
      },
      {
        tit: '身份证',
        state: 1,
        img: 'https://msion.xazbwl.com/static/applet/images/index/pho.png',
        tishi: '上传身份证照片'
      },
      {
        tit: '店头照',
        img: '',
        tishi: '上传店头照'
      },
      {
        tit: '免冠照',
        img: '',
        tishi: '上传免冠照'
      },
    ],
    zzxx: '', //店铺营业执照
    photo: [], //其他证照
    dtz: [], //店头照
    mgz: [], //免冠照
    dianname: '', //店铺名字
    fapename: '', //法人姓名
    xinyong: '', //信用代码
    xiangadress: '', //详细地址
    yyzz: '', //营业执照
    sfzZM: '', //身份证正面
    sfzFM:'', // 身份证反面
    wusfzFM:'', // 无域名身份证反面
    diantz: '', //店头照
    miangz: '', //免冠照
    pid: '', //省id
    cid: '', //市id
    quid: '', //区id
    mobile: '', //手机号
    shopType: '', //0个体  1企业
    hangyeid: '', //行业类别id
    yetaiid: '', //业态分类id
    otherhyid: 0, //其他行业id
    jgsid: '', //监管所id
    scjdid: '', //市场街道id
    jgyid: '', //监管员id
    wudiantz: '', //不带域名店头照
    wuyyzz: '', //不带域名营业执照
     wusfzZM: '', //不带域名身份证
    wumiangz: '', //不带域名免冠照
    dianplogo: '', //店头照
    wudianplogo: '', //店头照
    fdaaa: '',
    fdimg: '',

    otherhyxm: '', //其他行业name暂存数据
    otherhyno: '', //其他行业id暂存数据
    showModalStatus: false,
    selectname: '',
    jtqxqshow:'',
    checkValue:'',
    industryRemarks:'',   // 行业类别为其他时 的备注
    importType:'', // 控制所在区域自己选还是默认


    shopListS:[], // 商场市场列表
    shopListSName:'请选择商场市场',
    shopListSNameId:'',

    shianxianList:[{name:"是",id:1},{name:"否",id:0}],
    shianxian:'请选择是否购买食安险',
    shianxianid:'',
    waimai:'请选择是否有外卖服务',
    waimaiid:'',
    waimaipt:"请选择外卖平台",
    waimaiptid:'',
    showpopup:false,
    xuanz_qita2:''
  },
  onClose() {
    this.setData({ showpopup: false });
  },
  openpouper(){
    this.setData({ showpopup: true });

  },
  showModal(e) {
    var aaa = e.currentTarget.dataset.aaa
    var img = e.currentTarget.dataset.img
    this.setData({
      fdaaa: aaa,
      fdimg: img
    })
    let {
      type
    } = e.currentTarget.dataset, va = '';
    if (type == 's2') {
      va = "s2";
    }
    this.setData({
      [va]: true
    })
  },
 
  confirmbtn(e) {
    console.log(e)
    console.log('点击了从新上传！')
    var aaa = this.data.fdaaa
    var that = this;
    this.myChooseImage(1).then(res => {
      const tempFilePaths = res.tempFilePaths
      this.myUploadImg(tempFilePaths[0], 'file').then(res => {
        var data = JSON.parse(res.data)
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })
        var urls = data.httpUrl + data.imgUrl
        //营业执照
        if (aaa == 5) {
          that.yjsbyyz(data.imgUrl);
          that.setData({
            yyzz: urls,
            wuyyzz: data.imgUrl
          })
        }
        //身份证
        if (aaa == 6) {
          that.setData({
            sfzZM: urls,
            wusfzZM: data.imgUrl
          })
        }
        // 店头照
        if (aaa == 7) {
          that.setData({
            diantz: urls,
            wudiantz: data.imgUrl
          })
        }
        // 免冠照
        if (aaa == 8) {
          that.setData({
            miangz: urls,
            wumiangz: data.imgUrl
          })
        }
        // 支付码照片
        if(aaa == 18){
            debugger
            that.setData({
                Paymentcode:urls,
                wuPaymentcode:data.imgUrl
            })
        }
        // 店铺logo
        if (aaa == 9) {
          that.setData({
            dianplogo: urls,
            wudianplogo: data.imgUrl
          })
        }
      })
    })

  },
  cancelBtn() {
    console.log('点击了放大！')
    wx.previewImage({
      urls: [this.data.fdimg]
    })
  },
  getIptValue(e) {
    console.log(e.detail)
  },
  // 保存验证
  baocun() {
    if (this.data.dianname == '') {
      wx.showToast({
        title: '店铺/企业名称不能为空',
        icon: 'none'
      })
    } else if (this.data.fapename == '') {
      wx.showToast({
        title: '法人/负责人不能为空',
        icon: 'none'
      })
    } else if (this.data.xinyong == '') {
      wx.showToast({
        title: '社会信用代码不能为空',
        icon: 'none'
      })
    } else if (this.data.shopType == 0 && this.data.hangyeid == '') {
      wx.showToast({
        title: '请选择行业类别',
        icon: 'none'
      })
    } else if (this.data.shopType == 0 && this.data.hangyeid == 13 && this.data.yetaiid == '') {
      wx.showToast({
        title: '请选择业态分类',
        icon: 'none'
      })
    } else if (this.data.checkValue == undefined) {
      wx.showToast({
        title: '请选择其他行业',
        icon: 'none'
      })
    } else if (this.data.shengguo == '请选择省') {
      wx.showToast({
        title: '请选择省',
        icon: 'none'
      })
    } else if (this.data.shiguo == '请选择市') {
      wx.showToast({
        title: '请选择市',
        icon: 'none'
      })
    } else if (this.data.quguo == '请选择区') {
      wx.showToast({
        title: '请选择区',
        icon: 'none'
      })
    } else if (this.data.xiangadress == '') {
      wx.showToast({
        title: '详细地址不能为空',
        icon: 'none'
      })
    } else if (this.data.jiangsguo == '请选择所属监管所') {
      wx.showToast({
        title: '请选择所属监管所',
        icon: 'none'
      })
    } 
    // else if (this.data.jieguo == '请选择所属市场') {
    //  this.setData({
    //   jieguo:''
    //  })
    // } 
    // else if (this.data.myjgyguo == '请选择我的网格员') {
    //   wx.showToast({
    //     title: '请选择我的网格员',
    //     icon: 'none'
    //   })
    // } 
    else if (this.data.wuyyzz == '') {
      wx.showToast({
        title: '请上传营业执照',
        icon: 'none'
      })
    }
    //  else if (this.data.wusfz == '') {
    //   wx.showToast({
    //     title: '请上传身份证',
    //     icon: 'none'
    //   })
    // }
    else if (this.data.wudiantz == '') {
      wx.showToast({
        title: '请上传店头照',
        icon: 'none'
      })
    } 
    // else if (this.data.wumiangz == '') {
    //   wx.showToast({
    //     title: '请上传免冠照',
    //     icon: 'none'
    //   })
    // }
    else if(this.data.jtqxqshow == 1){
      if(this.data.cjzp == ''){
        wx.showToast({
          title: '请上传场景照片',
          icon: 'none'
        })
      }
      if(this.data.sfzZM == ''){
        wx.showToast({
          title: '请上传身份证正面',
          icon: 'none'
        })
      }
      if(this.data.sfzFM == ''){
        wx.showToast({
          title: '请上传身份证反面',
          icon: 'none'
        })
      }
      if(this.data.yhkZM == ''){
        wx.showToast({
          title: '请上传银行卡正面',
          icon: 'none'
        })
      }
      if(this.data.yhkFM == ''){
        wx.showToast({
          title: '请上传银行卡反面',
          icon: 'none'
        })
      }
    }
    //  return
      if (wx.getStorageSync('is_dings') == 0) {
    this.dingyuea()

        // this.dingyue()
      } else {
        this.que()
      }
    
  },
  dingyue() {
    if (!wx.getStorageSync('token')) {
      wx.showModal({
        title: '订阅消息需要授权哦~',
        cancelText: '取消',
        confirmText: '前往',
        success: function (res) {
          if (res.confirm) {
            console.log("确定")
            wx.navigateTo({
              url: '/page_zhu/shou/shou?sta=66',
            })
          } else {

          }
        }
      })
    } else {
      if (wx.getStorageSync('is_dings') == 0) {
        var hangyeid = this.data.hangyeid
        var yetaiid = this.data.yetaiid
        var shopType = this.data.shopType
        console.log('这里的商户类型',this.data.shopType)
        var mobile = this.data.mobile
        var dianname = this.data.dianname
        var fapename = this.data.fapename
        var xinyong = this.data.xinyong
        var pid = this.data.pid
        var cid = this.data.cid
        var quid = this.data.quid
        var xiangadress = this.data.xiangadress
        var jgsid = this.data.jgsid
        var scjdid = this.data.scjdid
        var jgyid = this.data.jgyid
        var wuyyzz = this.data.wuyyzz
        var wudiantz = this.data.wudiantz
        var wumiangz = this.data.wumiangz
        var checkValue = this.data.checkValue
        var wudiantz = this.data.wudiantz
      // areasId:that.data.jgsid,
      var  areasId = this.data.jgsid

        // 当用户没有点击 ’总是保持以上选择，不再询问‘  按钮。那每次执到这都会拉起授权弹窗
        wx.showModal({
          title: '提示',
          content: '请授权开通服务通知',
          showCancel: true,
          success: function (ress) {
            if (ress.confirm) {
              wx.requestSubscribeMessage({ // 调起消息订阅界面
                tmplIds: ['KSHQML6UP1xlkYCX0_BGtPdr5n_1sqEzypaL_bdwgkA'],
                success(res) {
                  if (res.KSHQML6UP1xlkYCX0_BGtPdr5n_1sqEzypaL_bdwgkA === "accept") {
                    console.log(res);
                    wx.request({
                      url: yuming + 'Besall/subscribe_save',
                      method: 'POST',
                      header: {
                        "content-type": "application/x-www-form-urlencoded",
                        token: wx.getStorageSync('token'),
                      },
                      data: {
                        // account: that.data.mobile,
                      },
                      success: function (res) {
                        console.log(res)
                        if (res.data.code == 200) {
                          wx.setStorageSync('is_dings', 1)
                          let hyid = 0;
                          if (hangyeid == 13) {
                            hyid = yetaiid
                          } else {
                            hyid = hangyeid
                          }
                          wx.request({
                            url: yuming + 'shop/shopAddInfo',
                            method: 'POST',
                            header: {
                              "content-type": "application/x-www-form-urlencoded",
                              token: wx.getStorageSync('token'),
                            },
                            data: {
                              areasId:areasId,
                              shopType: shopType,
                              mobile: mobile,
                              shopName: dianname,
                              legalPerson: fapename,
                              socialCode: xinyong,
                              stryId: hyid,
                              pid: pid,
                              cid: cid,
                              did: quid,
                              shopAddress: xiangadress,
                              regulatorOffice: jgsid,
                              regulatorStreet: scjdid,
                              shopSupervisor: jgyid,
                              businessLicense: wuyyzz,
                              // idcartLicenses: that.data.wusfz,
                              shopHeadPhoto: wudiantz,
                              bareheadedPhoto: wumiangz,
                              hangye_label: checkValue,
                              shopLogo: wudiantz,

                            },
                            success: function (res) {
                              wx.showToast({
                                title: res.data.msg,
                                icon: 'none'
                              })
                              if (res.data.code == 200) {
                                wx.setStorageSync('shopId', res.data.shopId)
                                setTimeout(function () {
                                  wx.reLaunch({
                                    url: '/pages/index/index',
                                  })
                                }, 1000)
                              }
                            },
                            fail: function () {
                              console.log("请求数据失败");
                            }
                          })
                        } else {
                          wx.setStorageSync('is_dings', 0)
                        }
                      },
                      fail: function () {
                        console.log("请求数据失败");
                      }
                    })
                  }


                },
                fail(er) {
                  console.log("订阅消息 失败 ");
                  console.log(er);
                  wx.setStorageSync('is_dings', 0)
                }
              })

            } else {
              wx.setStorageSync('is_dings', 0)
              let hyid = 0;
              if (hangyeid == 13) {
                hyid = yetaiid
              } else {
                hyid = hangyeid
              }
              wx.request({
                url: yuming + 'shop/shopAddInfo',
                method: 'POST',
                header: {
                  "content-type": "application/x-www-form-urlencoded",
                  token: wx.getStorageSync('token'),
                },
                data: {
                  areasId:areasId,

                  shopType: shopType,
                  mobile: mobile,
                  shopName: dianname,
                  legalPerson: fapename,
                  socialCode: xinyong,
                  stryId: hyid,
                  pid: pid,
                  cid: cid,
                  did: quid,
                  shopAddress: xiangadress,
                  regulatorOffice: jgsid,
                  regulatorStreet: scjdid,
                  shopSupervisor: jgyid,
                  businessLicense: wuyyzz,
                  // idcartLicenses: that.data.wusfz,
                  shopHeadPhoto: wudiantz,
                  bareheadedPhoto: wumiangz,
                  hangye_label: checkValue,
                  shopLogo: wudiantz
                },
                success: function (res) {
                  wx.showToast({
                    title: res.data.msg,
                    icon: 'none'
                  })
                  if (res.data.code == 200) {
                    wx.setStorageSync('shopId', res.data.shopId)
                    setTimeout(function () {
                      wx.reLaunch({
                        url: '/pages/index/index',
                      })
                    }, 1000)
                  }
                },
                fail: function () {
                  console.log("请求数据失败");
                }
              })
            }
          },
          fail(err) {
            wx.setStorageSync('is_dings', 0)
            let hyid = 0;
            if (hangyeid == 13) {
              hyid = yetaiid
            } else {
              hyid = hangyeid
            }
            wx.request({
              url: yuming + 'shop/shopAddInfo',
              method: 'POST',
              header: {
                "content-type": "application/x-www-form-urlencoded",
                token: wx.getStorageSync('token'),
              },
              data: {
                areasId:areasId,

                shopType: shopType,
                mobile: mobile,
                shopName: dianname,
                legalPerson: fapename,
                socialCode: xinyong,
                stryId: hyid,
                pid: pid,
                cid: cid,
                did: quid,
                shopAddress: xiangadress,
                regulatorOffice: jgsid,
                regulatorStreet: scjdid,
                shopSupervisor: jgyid,
                businessLicense: wuyyzz,
                // idcartLicenses: that.data.wusfz,
                shopHeadPhoto: wudiantz,
                bareheadedPhoto: wumiangz,
                hangye_label: checkValue,
                shopLogo: wudiantz
              },
              success: function (res) {
                wx.showToast({
                  title: res.data.msg,
                  icon: 'none'
                })
                if (res.data.code == 200) {
                  wx.setStorageSync('shopId', res.data.shopId)
                  setTimeout(function () {
                    wx.reLaunch({
                      url: '/pages/index/index',
                    })
                  }, 1000)
                }
              },
              fail: function () {
                console.log("请求数据失败");
              }
            })
          }
        })
      }

    }
  },
  // 点击确定接口
  que() {
    let that = this
    // that.dingyuea()
    console.log(that.data.wuPaymentcode);

    if(that.data.wuPaymentcode != ''){
        that.setData({
            pay_type: 1
          })
    }


    that.setData({
      buttonClicked: true
    })
    let hyid = 0;
    if (that.data.hangyeid == 13) {
      hyid = that.data.yetaiid
    } else {
      hyid = that.data.hangyeid
    }
    this.myRequest(yuming + 'shop/shopAddInfo', {
      areasId:that.data.jgsid,
      shopType: that.data.shopType,
      mobile: that.data.mobile,
      shopName: that.data.dianname,
      legalPerson: that.data.fapename,
      socialCode: that.data.xinyong,
      stryId: hyid,
      pid: that.data.pid,
      cid: that.data.cid,
      did: that.data.quid,
      shopAddress: that.data.xiangadress,
      regulatorOffice: that.data.jgsid,
      regulatorStreet: that.data.scjdid,
      shopSupervisor: that.data.jgyid,
      businessLicense: that.data.wuyyzz,
      // idcartLicenses: that.data.wusfz,
      shopHeadPhoto: that.data.wudiantz,
      bareheadedPhoto: that.data.wumiangz,
      hangye_label: that.data.checkValue,
      shopLogo: that.data.wudiantz,
      scenePhoto:that.data.wucjzp,
      idcartLicenses_z:that.data.sfzZM,
      idcartLicenses_f:that.data.sfzFM,
      bankcart_z:that.data.yhkZM,
      bankcart_f:that.data.yhkFM,
      pay_type:that.data.pay_type,
      pay_qrcode:that.data.wuPaymentcode,
      hangye_ramrk:that.data.industryRemarks,
      unitId:that.data.shopListSNameId,
      businessId:that.data.yetaiguojylxid,
      is_dangerous:that.data.shianxianid,
      is_takeaway:that.data.waimaiid,
      takeawayIds:that.data.waimaiid?that.data.checkValue2.join(','):''

    }, 
    'POST').then(res => {
      console.log(res,"res")
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        wx.setStorageSync('shopId', res.data.shopId)
        setTimeout(function () {
          wx.reLaunch({
            url: '/pages/index/index',
          })
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }
    })
  },
  // 上传
  chuan(e) {
    var aaa = e.currentTarget.dataset.aaa //店头营业执照
    var that = this;
    this.myChooseImage(1).then(res => {
      const tempFilePaths = res.tempFilePaths
      this.myUploadImg(tempFilePaths[0], 'file').then(res => {
        var data = JSON.parse(res.data)
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })
        var urls = data.httpUrl + data.imgUrl
        //营业执照
        if (aaa == 5) {
          that.yjsbyyz(data.imgUrl);
          that.setData({
            yyzz: urls,
            wuyyzz: data.imgUrl
          })
        }

        if(aaa == 18){
            that.setData({
                Paymentcode:urls,
                wuPaymentcode:data.imgUrl
            })
        }
        //身份证 正面
        if (aaa == 6) {
          that.setData({
            sfzZM: urls,
            wusfzZM: data.imgUrl
          })
          // console.log(this.data.sfzZM);
        }
        // 身份证反面
        if (aaa == 13) {
          that.setData({
            sfzFM: urls,
            wusfzFM: data.imgUrl
          })
          // console.log(this.data.sfzZM);
        }
        // 银行卡正面
        if (aaa == 14) {
          that.setData({
            yhkZM: urls,
            wuyhkZM: data.imgUrl
          })
          // console.log(this.data.sfzZM);
        }
        // 银行卡反面
        if (aaa == 15) {
          that.setData({
            yhkFM: urls,
            wuyhkFM: data.imgUrl
          })
          // console.log(this.data.sfzZM);
        }
        // 场景照片
        if (aaa == 12) {
          that.setData({
            cjzp: urls,
            wucjzp: data.imgUrl
          })
          // console.log(this.data.sfzZM);
        }
        // 店头照
        if (aaa == 7) {
          that.setData({
            diantz: urls,
            wudiantz: data.imgUrl
          })
        }
        // 免冠照
        if (aaa == 8) {
          that.setData({
            miangz: urls,
            wumiangz: data.imgUrl
          })
        }
        // 店铺logo
        if (aaa == 9) {
          that.setData({
            dianplogo: urls,
            wudianplogo: data.imgUrl
          })
        }
      })
    })
  },
  // 上传图片
  // sctp(file) {
  //   wx.uploadFile({
  //     url: yuming + 'Besall/Upload',
  //     filePath: file,
  //     name: "image",
  //     header: {
  //       'Content-Type': 'application/x-www-form-urlencoded',
  //       'Token': wx.getStorageSync('token'),
  //     },
  //     formData: {
  //       file: file
  //     },
  //     success(res) {
  //       console.log(res)
  //       wx.showToast({
  //         title: res.data.msg,
  //         icon: 'none'
  //       })
  //     }
  //   })
  // },
  // 店铺名称
  dianname(e) {
    this.setData({
      dianname: e.detail.value
    })
  },
  // 法人
  fapename(e) {
    this.setData({
      fapename: e.detail.value
    })
  },
  // 信用代码
  xinyong(e) {
    const zhengze = /^[a-zA-Z0-9]+$/
    console.log(zhengze.test(e.detail.value));
    if(zhengze.test(e.detail.value) == true) {
      this.setData({
        xinyong: e.detail.value
      })
    }else{
      wx.showToast({
        title: '只能输入数字和字母',
        icon:'none'
      })
      this.setData({
        xinyong: ''
      })
    }
  },
  industryRemarks(e){
    this.setData({
        industryRemarks: e.detail.value
      })
  },
  mobelphone(e) {
    this.setData({
      mobelphone: e.detail.value
    })
  },
  // 详细地址
  xiangadress(e) {
    this.setData({
      xiangadress: e.detail.value
    })
  },
  // 行业类别
  hangs(e) {

    this.setData({
      hangyeguo: this.data.hanglist[e.detail.value].cartTitle,
      hangyeid: this.data.hanglist[e.detail.value].id,
      yetaiguo:'请选择业态分类',
      jylxList:[],
      yetaiguojylx:'请选择经营类型',
      waimaiid:'',
      waimaiptid:"",
      shianxianid:""
    });
    console.log(this.data.hangyeid)
    this.getytList();

    this.getRichText();

  },
  // 个体还是企业
  getiOrqy(e){
    this.setData({
        getiOrqyname:this.data.getiOrqy[e.detail.value].title,
        shopType:this.data.getiOrqy[e.detail.value].id
    })
    console.log(this.data.shopType);
    this.hylb() // 行业类别

  },
  yetais(e) {
    this.setData({
      yetaiguo: this.data.ytList[e.detail.value].cartTitle,
      yetaiid: this.data.ytList[e.detail.value].id,
    });
    console.log(this.data.yetaiguo)
    console.log(this.data.yetaiid)
    wx.setStorageSync('ytName', this.data.yetaiguo)
    this.getytList();
  },

  yetaisjylx(e){
    this.setData({
      yetaiguojylx: this.data.jylxList[e.detail.value].name,
      yetaiguojylxid: this.data.jylxList[e.detail.value].id,
    });
  },
  waimaiSelect(e){
    this.setData({
      waimai: this.data.shianxianList[e.detail.value].name,
      waimaiid: this.data.shianxianList[e.detail.value].id,
      xuanz_qita2:'',
      checkValue2:[],
      selectnames2:[]
    });
    this.waimaiserveList()
  },
  shianxianSelect(e){
    this.setData({
      shianxian: this.data.shianxianList[e.detail.value].name,
      shianxianid: this.data.shianxianList[e.detail.value].id,
    });
  },
  waimaiptSelect(e){
    this.setData({
      waimaipt: this.data.waimaiList[e.detail.value].name,
      waimaiptid:this.data.waimaiList[e.detail.value].id
    })
  },
  waimaiserveList(){
    this.myRequest(yuming + 'Shop/shop_takeaway',{

    },"POST").then(res=>{
      console.log(res);
      this.setData({
        waimaiList:res.data.data
      })
    })
  },
  // 其他行业类别
  otherhy(e) {
    this.setData({
      otherhyguo: this.data.otherhyList[e.detail.value].name,
      otherhyid: this.data.otherhyList[e.detail.value].id,
    });
  },
  getytList() {
    let that = this
    this.myRequest(yuming + 'Besall/cartrelationList', {
      typeMold: 2,
      fid: that.data.hangyeid
    }, 'POST').then(res => {
      that.setData({
        ytList: res.data.data,
      })
    })
  },
  // 所属市场
  jies(e) {
    var id = this.data.myjgylist[e.detail.value].areaId
    console.log(id);
    this.myRequest(yuming + 'Besall/areaList', {
      parentId: id,
      areaType: 5,
  }, 'POST').then(res => {
      console.log(res.data.data);
      this.setData({
      aaaa: res.data.data
    })
  })
    this.setData({
      myjgyguo: this.data.myjgylist[e.detail.value].areaName,
      scjdid: id
    })
    this.jgy(id)
    // console.log(this.data.scjdid);
  },
  // 所属监管所
  bindjiangs(e) {
    var id = this.data.jiangslist[e.detail.value].areaId
    var fenjuOrsuo = this.data.jiangslist[e.detail.value].fenjuOrsuo
    console.log(e);
    this.getshopListS(id)
    console.log(fenjuOrsuo);
    if(fenjuOrsuo == 1){
        this.setData({
            suoshufenju:true,
            jiangsguo: this.data.jiangslist[e.detail.value].areaName,
            jgsid: id,
            jieguo: '请选择所属市场/街道',
            scjdid: '',
            myjgyguo: '请选择',
            jgyid: '',
        })
        this.jianguansuotwo()
    }else{
        this.setData({
            jiangsguo: this.data.jiangslist[e.detail.value].areaName,
            jgsid: id,
            jieguo: '请选择所属市场/街道',
            scjdid: '',
            myjgyguo: '请选择',
            jgyid: '',
          })
          this.shsc(id)
          this.jgy(id)
      
    }
   
  },
  bindjiangsTWo(e){
    var id = this.data.jianguansuoTWO[e.detail.value].areaId
    this.setData({
        jianguansuoTWOname: this.data.jianguansuoTWO[e.detail.value].areaName,
        // jgsid: id,
        jgsidTWO:id,
        // jieguo: '请选择所属市场/街道',
        scjdid: '',
        myjgyguo: '请选择',
        jgyid: '',
      })
      this.jgytwo(id)

  },
  bindmyjgyJH(e){
    this.setData({
      myjgyguoJH: this.data.aaaa[e.detail.value].areaName,
      jgyid: this.data.aaaa[e.detail.value].areaId
    })
  },
  // 我的监管员
  bindmyjgy(e) {
    this.setData({
      myjgyguo: this.data.myjgylist[e.detail.value].areaName,
      jgyid: this.data.myjgylist[e.detail.value].areaId
    })

  },

  bindShops(e){
    this.setData({
      shopListSName:this.data.shopListS[e.detail.value].name,
      shopListSNameId:this.data.shopListS[e.detail.value].id
    })
    console.log(this.data.shopListSName,this.data.shopListSNameId);
  },
  // 省
  bindsheng(e) {
    var id = this.data.shenglist[e.detail.value].areaId
    this.setData({
      shengguo: this.data.shenglist[e.detail.value].areaName,
      pid: id,
      shiguo: '请选择市',
      cid: '',
      suoshufenju:false,
      quguo: '请选择区',
      quid: '',
      jiangsguo: '请选择所属监管所',
      jgsid: '',
      jieguo: '请选择所属市场/街道',
      scjdid: '',
      myjgyguo: '请选择',
      jgyid: ''
    })
    this.getCity(id)
  },
  // 市
  bindshi(e) {
    var id = this.data.shilist[e.detail.value].areaId
    if (this.data.shengguo == '请选择省') {
      wx.showToast({
        title: '请选择省',
        icon: 'none'
      })
    } else {
      this.setData({
        shiguo: this.data.shilist[e.detail.value].areaName,
        cid: id,
        suoshufenju:false,

        quguo: '请选择区',
        quid: '',
        jiangsguo: '请选择所属监管所',
        jgsid: '',
        jieguo: '请选择所属市场/街道',
        scjdid: '',
        myjgyguo: '请选择',
        jgyid: ''
      })
      this.getArea(id)
    }
  },
  // 区
  bindqu(e) {
    if (this.data.shiguo == '请选择市') {
      wx.showToast({
        title: '请选择市',
        icon: 'none'
      })
    } else {
      this.setData({
        suoshufenju:false,

        quguo: this.data.qulist[e.detail.value].areaName,
        quid: this.data.qulist[e.detail.value].areaId,
        jtqxqshow:this.data.qulist[e.detail.value].registerTab,
        jiangsguo: '请选择所属监管所',
        jgsid: '',
        jieguo: '请选择所属市场/街道',
        scjdid: '',
        myjgyguo: '请选择',
        jgyid: ''
      })
      this.jgs(0)
    }
  },
  //营业执照一键识别
  yjsbyyz(imgurl) {
    wx.showLoading({
      title: '识别营业执照中',
      icon: 'none'
    })
    let that = this
    this.myRequest(yuming + 'Baiduapi/identify_trade', {
      imgUrl: imgurl
    }, "POST").then(res => {
      console.log(res)
      if (res.data.code == 200) {
        wx.showToast({
          title: res.data.data.营业执照识别状态,
          icon: 'none'
        })
        wx.hideLoading();
        let data = res.data.data.words_result
        that.setData({
          dianname: data.单位名称.words,
          fapename: data.法人.words,
          xinyong: data.社会信用代码.words,
          // shengguo: data.企业所在省份,
          // shiguo: data.企业所在城市,
          // quguo: data.企业所在区域,
          // xiangadress: data.地址.words,
        })
        // if (data.企业所在省份 != '' && data.企业所在城市 != '' && data.企业所在区域 != '') {
        //   let pid = that.data.shenglist.filter(item => item.areaName == that.data.shengguo)[0].areaId;
        //   that.setData({
        //     pid: pid
        //   })
        //   that.doCity(pid);
        // } else {
        //   let shengguo = ''
        //   let shiguo = ''
        //   let quguo = ''
        //   if (data.企业所在省份 == '') {
        //     shengguo = '请选择省'
        //   }
        //   if (data.企业所在城市 == '') {
        //     shiguo = '请选择市'
        //   }
        //   if (data.企业所在区域 == '') {
        //     quguo = '请选择区'
        //   }
        //   this.setData({
        //     shengguo,
        //     shiguo,
        //     quguo
        //   })
        // }
      }
    })
  },
  async doCity(pid) {
    await this.getCity(pid);
    console.log(this.data.shilist);
    let cid = this.data.shilist.filter(item => item.areaName == this.data.shiguo)[0].areaId;
    this.setData({
      cid: cid
    })
    this.doArea(cid);
  },
  async doArea(cid) {
    await this.getArea(cid);
    console.log(this.data.qulist);
    let quid = this.data.qulist.filter(item => item.areaName == this.data.quguo)[0].areaId;
    this.setData({
      quid: quid
    })
    this.jgs(0);
  },
  // 返回
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  // 行业类别查询
  hylb() {
    var that = this
    var typeMold = ''
    var shopType = this.data.shopType
    if (shopType == 0) { //0个体 1企业
      typeMold = 2 //1企业 2个体户
    }
    if (shopType == 1) {
      typeMold = 1
    }
    this.myRequest(yuming + 'Besall/cartrelationList', {
      typeMold: typeMold
    }, 'POST').then(res => {
      if (res.data.code == 200) {
        // let otherhyList = res.data.hangyeLabel;
        // otherhyList.forEach(item => {
        //   item.checked = false;
        // })
        this.setData({
          hanglist: res.data.data,
          otherhyList: res.data.hangyeLabel
        })
        console.log(this.data.otherhyList)
        if (this.data.hangyeid) {
          this.setData({
            hangyeguo: this.data.hanglist.find(item => item.id == this.data.hangyeid).cartTitle
          })
          this.getytList();
        }
      }
    })
  },
  // 获取省列表
  getProvince: function () {
    let that = this
    this.myRequest(yuming + 'Besall/areaList', {
      parentId: 0,
      areaType: 0,
    }, 'POST').then(res => {
      that.setData({
        shenglist: res.data.data, //省级原始数据
        importType:res.data.type
      })


      // if(res.data.type == 1){
      //   that.setData({
      //     shengguo:res.data.city.sheng[0].areaName,  // 省
      //     shiguo:res.data.city.shi[0].areaName,   // 市
      //     quguo:res.data.city.county[0].areaName,  // 区
      //     jiangslist:res.data.city.superlst,   //  监管所列表
      //     pid: res.data.city.sheng[0].areaId, //省id
      //     cid: res.data.city.shi[0].areaId, //市id
      //     quid: res.data.city.county[0].areaId, //区id
      //   })
      // }
      // let defaultCode = that.data.shenglist[0].areaId  //使用第一项当作参数获取市级数据
      // if (defaultCode) {
      //   that.getCity(defaultCode) //获取市区数据
      // }


    })
  },
  //获取市列表
  getCity: function (id) {
    return new Promise((resolve, reject) => {
      let that = this
      this.myRequest(yuming + 'Besall/areaList', {
        parentId: id,
        areaType: 1,
      }, 'POST').then(res => {
        that.setData({
          shilist: res.data.data, //保持市级数据
        })
        let defaultCode = that.data.shilist[0].areaId //获取第一个市的区级数据
        if (defaultCode) {
          that.getArea(defaultCode) //获取区域数据
        }
        resolve(res);
      }).catch(err => {
        reject(err);
      })
    })
  },
  //获取区列表
  getArea: function (id) {
    return new Promise((resolve, reject) => {
      let that = this
      this.myRequest(yuming + 'Besall/areaList', {
        parentId: id,
        areaType: 2,
      }, 'POST').then(res => {
        that.setData({
          qulist: res.data.data, //区列表
          quid: res.data.data[0].areaId
        })
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  // 点击区获取所属监管所
  jgs(id) {
    let that = this
    this.myRequest(yuming + 'Besall/areaList', {
        parentId: that.data.quid,
        areaType: 3,
    }, 'POST').then(res => {
      that.setData({
        jiangslist: res.data.data
      })
    })
  },

  getshopListS(id){
    let that = this 
    this.myRequest(yuming + 'Besall/areas_unit_list',{
      areaId:id
    },'POST').then(res =>{
      that.setData({
        shopListS:res.data.data
      })
    })
  },


  // 所属市场
  shsc(id) {
    let that = this
    this.myRequest(yuming + 'shop/shopAreaMarketerList', {
      cityId: that.data.jgsid,
      fid: id
    }, 'POST').then(res => {
      that.setData({
        jielist: res.data.data
      })
    })
  },
  jianguansuotwo(){
    let that = this 
    this.myRequest(yuming + 'Besall/areaList',{
        parentId: that.data.jgsid,
        areaType: 4,
    },'POST').then(res=>{
        console.log(res.data.data);
        that.setData({
            jianguansuoTWO : res.data.data
        })
    })
  },
  // 监管员
  jgy(id) {
    let that = this
    this.myRequest(yuming + 'Besall/areaList', {
        parentId: that.data.jgsid,
        areaType: 4,
    }, 'POST').then(res => {
      that.setData({
        myjgylist: res.data.data
      })
    })
  },
 // 网格员  --------两个监管所之后的
 jgytwo(id) {
    let that = this
    this.myRequest(yuming + 'Besall/areaList', {
        parentId: that.data.jgsidTWO,
        areaType: 5,
    }, 'POST').then(res => {
        console.log(res.data.data);
      that.setData({
        myjgylisttwo: res.data.data
      })
    })
  },


  //点击我显示底部弹出框
  clickme: function () {
    this.showTan();
  },
  clickme2: function () {
    this.showTan2();
  },
  //显示对话框
  showTan2: function () {
    // 显示遮罩层
    var animation2 = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation2 = animation2
    animation2.translateY(300).step()
    this.setData({
      animationData2: animation2.export(),
      showModalStatus2: true,
    })
    setTimeout(function () {
      animation2.translateY(0).step()
      this.setData({
        animationData2: animation2.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal2: function () {
    // 隐藏遮罩层
    var animation2 = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation2 = animation2
    animation2.translateY(300).step()
    this.setData({
      animationData2: animation2.export(),
      op: true,
      oi: false
    })
    setTimeout(function () {
      animation2.translateY(0).step()
      this.setData({
        animationData2: animation2.export(),
        showModalStatus2: false
      })
    }.bind(this), 200)
  },
  selected2() {
    let waimaiguo = '';
    if (this.data.waimaiList != '') {
      waimaiguo = this.data.waimaiList
    } else {
      waimaiguo = '请选择外卖分类'
    }
    this.setData({
      waimaiguo,
      showModalStatus2: false,
      op2: false,
      oi2: true,
      xuanz_qita2: this.data.selectnames2.toString()
    })
    console.log()
  },
  checkboxChange2: function (e) {
    this.setData({
      oi2: true,
      op2: false
    })
    var item = e.detail.value
    var checkValue = []; //选中的id
    var selectnames = []; //选中的name
    for (var i = 0; i < item.length; i++) {
      var selectrow = item[i].split(",") //数组以逗号分割
      checkValue = checkValue.concat(selectrow[0]) //第一个为id
      selectnames = selectnames.concat(selectrow[1]) //第二个为name
    }
    console.log('选中的id',selectnames,e)
    this.setData({
      checkValue2: checkValue,
      selectnames2: selectnames
    })
  },
  checkbox2: function (e) {
    var index = e.currentTarget.dataset.index; //获取当前点击的下标
    var waimaiList = this.data.waimaiList; //选项集合
    waimaiList[index].checked = !waimaiList[index].checked; //改变当前选中的checked值
    this.setData({
      waimaiList: waimaiList,
    });
    console.log(this.data.name)
  },
  //显示对话框
  showTan: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    // if (this.data.otherhyid) {
    //   let otherhyList = this.data.otherhyList;
    //   let otherhyid = this.data.otherhyid.split(',')
    //   otherhyList.forEach(item => {
    //     item.checked = false;
    //     otherhyid.forEach(items => {
    //       if (items == item.id) {
    //         item.checked = true
    //       }
    //     })
    //   })
    //   this.setData({
    //     otherhyxm: this.data.otherhyguo,
    //     otherhyno: this.data.otherhyid,
    //     otherhyList
    //   })
    // } else {
    //   this.data.otherhyList.forEach(item => {
    //     item.checked = false
    //   })
    //   this.setData({
    //     otherhyList: this.data.otherhyList
    //   })
    // }
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },
  selected() {
    let otherhyguo = '';
    if (this.data.otherhyxm != '') {
      otherhyguo = this.data.otherhyxm
    } else {
      otherhyguo = '请选择其他行业分类'
    }
    this.setData({
      otherhyguo,
      otherhyid: this.data.otherhyno,
      showModalStatus: false
    })
  },
  //多选
  userCheck: function (e) {
    let index = e.currentTarget.dataset.id; //获取用户当前选中的索引值
    let Box = this.data.otherhyList
    if (Box[index].checked) {
      this.data.otherhyList[index].checked = false;
    } else {
      this.data.otherhyList[index].checked = true;
    }
    this.setData({
      otherhyList: this.data.otherhyList
    })
    // 返回用户选中的值
    let value = Box.filter((item, index) => {
      return item.checked == true;
    })
    let xditem = '';
    let xdid = '';
    value.forEach((item, index) => {
      xditem += item.name + ','
      xdid += item.id + ','
    })
    if (xditem.slice(-1) == ',') {
      xditem = xditem.slice(0, xditem.length - 1);
    }
    if (xdid.slice(-1) == ',') {
      xdid = xdid.slice(0, xdid.length - 1);
    }
    this.setData({
      otherhyxm: xditem,
      otherhyno: xdid,
    })
    console.log(this.data.otherhyList)
  },
  checkbox: function (e) {
    var index = e.currentTarget.dataset.index; //获取当前点击的下标
    var otherhyList = this.data.otherhyList; //选项集合
    otherhyList[index].checked = !otherhyList[index].checked; //改变当前选中的checked值
    this.setData({
      otherhyList: otherhyList
    });
  },
  checkboxChange: function (e) {
    var item = e.detail.value
    var checkValue = []; //选中的id
    var selectname = []; //选中的name
    for (var i = 0; i < item.length; i++) {
      var selectrow = item[i].split(",") //数组以逗号分割
      checkValue = checkValue.concat(selectrow[0]) //第一个为id
      selectname = selectname.concat(selectrow[1]) //第二个为name
    }
    this.setData({
      checkValue: checkValue,
      selectname: selectname
    })
    console.log(this.data.checkValue)
    console.log(this.data.selectname)
    // var checkValue = e.detail.value;
    // this.setData({
    //   checkValue: checkValue
    // });
  },
  getRichText(){
    this.myRequest(yuming + '/Besall/shop_register_business',{},'POST').then((res)=>{
      console.log(res);
      this.setData({
        content:res.data.content,
        jylxList:res.data.data
      })
      if(this.data.hangyeid == 6){

        const janeObj = this.data.jylxList.find(obj => obj.id == 2)
        console.log(janeObj.sub);
        this.setData({
          
          jylxList:janeObj.sub
        })
        console.log(this.data.jylxList);
        return
      } 
      if(this.data.hangyeid == 13){
  
        const janeObj = this.data.jylxList.find(obj => obj.id == 1)
        console.log(janeObj.sub);
        this.setData({
          jylxList:janeObj.sub
        })
        console.log(this.data.jylxList);
        return
  
      } 
      // console.log(this.data.content);
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRichText()

    console.log(options)
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      mobile: options.mobile,
      shopType: options.shopType,
      title: options.title
    })
    if (options.hangyeid) {
      wx.setStorageSync('stryId', options.hangyeid)
    }
    this.setData({
      hangyeid: wx.getStorageSync('stryId')
    })
   this.hylb() // 行业类别
    this.getProvince() //获取省
  },
  dingyuea() {
    if (!wx.getStorageSync('token')) {
      wx.showModal({
        title: '订阅监管消息需要授权哦~',
        cancelText: '取消',
        confirmText: '前往',
        success: function (res) {
          if (res.confirm) {
            console.log("确定")
            wx.navigateTo({
              url: '/page_zhu/shou/shou?sta=66',
            })
          } else {

          }
        }
      })
    } else {
      if (wx.getStorageSync('is_dings') == 0) {
        var hangyeid = this.data.hangyeid
        var yetaiid = this.data.yetaiid
        var shopType = this.data.shopType
        var mobile = this.data.mobile
        var dianname = this.data.dianname
        var fapename = this.data.fapename
        var xinyong = this.data.xinyong
        var pid = this.data.pid
        var cid = this.data.cid
        var quid = this.data.quid
        var xiangadress = this.data.xiangadress
        var jgsid = this.data.jgsid
        var scjdid = this.data.scjdid
        var jgyid = this.data.jgyid
        var wuyyzz = this.data.wuyyzz
        var wudiantz = this.data.wudiantz
        var wumiangz = this.data.wumiangz
        var checkValue = this.data.checkValue
        var wudiantz = this.data.wudiantz
        let that = this
        wx.showModal({
          title: '提示',
          content: '请授权开通服务通知',
          showCancel: true,
          success: function (ress) {
            if (ress.confirm) {
              wx.requestSubscribeMessage({ // 调起消息订阅界面
                tmplIds: ['R7oMsez70p70P1ZERDutvNEM2E8dTqV-Lz8ClqkzZ9s'],
                success(res) {
                  if (res["R7oMsez70p70P1ZERDutvNEM2E8dTqV-Lz8ClqkzZ9s"] === "accept") {
                    console.log(res);
                    wx.request({
                      url: yuming + 'Besall/subscribe_save',
                      method: 'POST',
                      header: {
                        "content-type": "application/x-www-form-urlencoded",
                        token: wx.getStorageSync('token'),
                      },
                      data: {
                        // account: that.data.mobile,
                      },
                      success: function (res) {
                        console.log(res)
                        if (res.data.code == 200) {
                          wx.setStorageSync('is_dings', 1)
                            that.que()

                        } else {
                          wx.setStorageSync('is_dings', 0)
                          that.que()

                        }
                      },
                      fail: function () {
                        console.log("请求数据失败");
                      }
                    })
                  }


                },
                fail(er) {
                  console.log("订阅消息 失败 ");
                  console.log(er);
                  wx.setStorageSync('is_dings', 0)
                  this.que()

                }
              })

            }
          }
        })
      }

    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})